﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace BeanboxSoftware.BeanMap
{
  namespace Internal
  {
    public abstract partial class MapBase<TGen, TValue, TPrimaryKey, TPrimaryValue>
    {
      internal class MapBaseDebuggerProxyAccess
      {
        protected MapBase<TGen, TValue, TPrimaryKey, TPrimaryValue> _base;
        public TValue DefaultValue { get { return _base._defaultValue; } }
        public TGen DefaultGeneration { get { return _base._defaultGeneration; } }

        public MapBaseDebuggerProxyAccess(MapBase<TGen, TValue, TPrimaryKey, TPrimaryValue> mbase)
        {
          _base = mbase;
        }
      }
    }
  }

  [DebuggerTypeProxy(typeof(Map<,>.MapDebuggerProxy))]
  [DebuggerDisplay("Count = {Count}")]
  public partial class Map<K, V>
  {
    [DebuggerDisplay("{Key}, {Value}")]
    internal class KeyValueViewer
    {
      public K Key;
      public V Value;
      public override string ToString()
      {
        return string.Format("{0}, {1}", Key, Value);
      }
    }

    internal class MapDebuggerProxy
    {
      private Map<K, V> _map;
      private MapBaseDebuggerProxyAccess _access;

      public KeyNotFoundBehavior KeyNotFoundBehavior { get { return _map.KeyNotFoundBehavior; } }
      public Func<K, V> DefaultGeneration { get { return _access.DefaultGeneration; } }
      public V DefaultValue { get { return _access.DefaultValue; } }

      [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
      public KeyValueViewer[] ZItems
      {
        get
        {
          return _map.Select(kvp => new KeyValueViewer { Key = kvp.Key, Value = kvp.Value }).ToArray();
        }
      }

      public MapDebuggerProxy(Map<K, V> map)
      {
        _map = map;
        _access = new MapBaseDebuggerProxyAccess(_map);
      }
    }
  }

  [DebuggerTypeProxy(typeof(Map<,,>.MapDebuggerProxy))]
  [DebuggerDisplay("Count = {Count}")]
  public partial class Map<K1, K2, V>
  {
    [DebuggerDisplay("[{Key1}, {Key2}], {Value}")]
    internal class KeyValueViewer
    {
      public K1 Key1;
      public K2 Key2;
      public V Value;
      public override string ToString()
      {
        return string.Format("[{0}, {1}], {2}", Key1, Key2, Value);
      }
    }

    internal class MapDebuggerProxy
    {
      private Map<K1, K2, V> _map;
      private MapBaseDebuggerProxyAccess _access;

      public KeyNotFoundBehavior KeyNotFoundBehavior { get { return _map.KeyNotFoundBehavior; } }
      public Func<K1, K2, V> DefaultGeneration { get { return _access.DefaultGeneration; } }
      public V DefaultValue { get { return _access.DefaultValue; } }

      [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
      public KeyValueViewer[] ZItems
      {
        get
        {
          return _map.KeyValues.Select(kvp => new KeyValueViewer { Key1 = kvp.Key.Item1, Key2 = kvp.Key.Item2, Value = kvp.Value }).ToArray();
        }
      }

      public MapDebuggerProxy(Map<K1, K2, V> map)
      {
        _map = map;
        _access = new MapBaseDebuggerProxyAccess(_map);
      }
    }
  }

  [DebuggerTypeProxy(typeof(Map<,,,>.MapDebuggerProxy))]
  [DebuggerDisplay("Count = {Count}")]
  public partial class Map<K1, K2, K3, V>
  {
    [DebuggerDisplay("[{Key1}, {Key2}, {Key3}], {Value}")]
    internal class KeyValueViewer
    {
      public K1 Key1;
      public K2 Key2;
      public K3 Key3;
      public V Value;
      public override string ToString()
      {
        return string.Format("[{0}, {1}, {2}], {3}", Key1, Key2, Key3, Value);
      }
    }

    internal class MapDebuggerProxy
    {
      private Map<K1, K2, K3, V> _map;
      private MapBaseDebuggerProxyAccess _access;

      public KeyNotFoundBehavior KeyNotFoundBehavior { get { return _map.KeyNotFoundBehavior; } }
      public Func<K1, K2, K3, V> DefaultGeneration { get { return _access.DefaultGeneration; } }
      public V DefaultValue { get { return _access.DefaultValue; } }

      [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
      public KeyValueViewer[] ZItems
      {
        get
        {
          return _map.KeyValues.Select(kvp => new KeyValueViewer { Key1 = kvp.Key.Item1, Key2 = kvp.Key.Item2, Key3 = kvp.Key.Item3, Value = kvp.Value }).ToArray();
        }
      }

      public MapDebuggerProxy(Map<K1, K2, K3, V> map)
      {
        _map = map;
        _access = new MapBaseDebuggerProxyAccess(_map);
      }
    }
  }
}